:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Switching the Maven environment.
:: 
:: Author: ZHANGQ
:: Create Time: 2020-06-26
:: Update Time: 2020-09-29
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

@ECHO OFF

:: recover old environment
CALL inactivate-maven.bat

:: backup current environment
SET PATH_BEFORE_MAVEN=%PATH%
SET PROMPT_BEFORE_MAVEN=%PROMPT%
ECHO Backing up the current environment 'PATH' and 'PROMPT' for maven.

:: whether jdk environment has set
IF NOT DEFINED JAVA_HOME (
    ECHO No JDK is available in the current environment.
    ECHO Setting Zulu OpenJDK 8 with UTF8 for chinese environment.
    :: call zulu jdk chinese environment 8 set
    CALL activate-utf8-cn-zulu8.bat

    :: sign for java environment variables set from maven environment set
    SET JAVA_ENV_SET_FROM_MAVEN=Y
)

:: set new environment variables
SET MAVEN_HOME=C:\Apache\Maven
SET M2_HOME=%MAVEN_HOME%
ECHO Setting 'MAVEN_HOME' and 'M2_HOME' environment variable.
SET PATH=%MAVEN_HOME%\bin;%PATH%
ECHO Setting 'PATH' environment variable for maven.

:: set command line prompt
FOR /F "tokens=2 delims=()" %%a IN ("%PROMPT%") DO SET ENV_PROMPT=%%a
SET PROMPT=(%ENV_PROMPT% MAVEN) $P$G
ECHO Setting the command line prompt for maven.
